<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     pagizer
 * @subpackage  website
 */

/**
 * Class to delete a block from a page 
 */
class m_website_actions_AjaxDeleteBlockAction extends m_backoffice_extends_Action
{
	public function execute()
	{
		
		$tempDocService = m_backoffice_services_TempDocService::getInstance();
		
		// Retrieved from jQueryBackend deleteBlock
		$pageId = $this->getRequestParameter('docId');		
		$pageLang = $this->getRequestParameter('docLang');		
		$blockId = $this->getRequestParameter("blockId");
		
		// If page is in temporary table get it
		if($tempDocService->hasTemporary($pageId, $pageLang))
		{
			$page = $tempDocService->getTemporaryDocument($pageId, $pageLang);
		}
		else
		{
			$page = f_document_Provider::getInstance()->getByModelAndUniqueId('website/Page', $pageId, $pageLang);			
		}
	
		$block = $page->getBlockById($blockId);
		
		$block['blockStatus'] = "DELETED";

		$page->setBlockParamsById($blockId, $block);
		
		$tempDocService->saveTemporaryDocument($page);
	}	
	
	public function validate()
	{
		return $this->getUserContext()->hasRight(array("backoffice_accessBo", "website_TabPageStructure"));
	}

	public function errorHandler()
	{
		return null;
	}
}